<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <ui:composition template="/template_bill.xhtml"
                    >
        <ui:define name="body">
            <p:growl id="growl" showDetail="true" sticky="true" /> 
             <h:outputScript name="js/treasuryjs.js" />
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <!-- start of the photos bar -->
            <div class="clear"></div>

            <!-- start of the search form -->
            <h:form styleClass="form-inline well" id="myform">
                <label style="padding-left: 19px;" for="fromDate">من</label>
                <p:calendar id="fromDate" style="padding-left: 45px;" value="#{inventoryStoreController.fromDate}"  showOn="button" pattern="dd/MM/yyyy" required="true" requiredMessage="من فضلك أدخل التاريخ الأول"/>
                <label style="padding-left: 19px;" for="toDate">الى</label>
                <p:calendar id="toDate" style="padding-left: 45px;" value="#{inventoryStoreController.toDate}"  showOn="button" pattern="dd/MM/yyyy" required="true" requiredMessage="من فضلك أدخل التاريخ الثانى"/>
                <div class="clear"></div>
                <h:inputHidden value="#{inventoryStoreController.hiddenField}" id="hidfiled"/>
                <h:commandLink style="margin-right: 300px;" styleClass="btn-primary btn" action="#{inventoryStoreController.getInventory}" value="عرض" onclick="" />
            </h:form>
            <!-- end of the search form -->


            <!-- start of the table -->
            <h:form >
                <h:panelGroup rendered="#{inventoryStoreController.items.rowCount > 0}">
                    <p:dataTable var="items" value="#{inventoryStoreController.items}" paginator="true" rows="50"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="50,100,150">  

                        <f:facet name="header">  
                            جرد المخازن 
                        </f:facet>   
                        <p:columnGroup type="header">
                            <p:row>
                                <p:column  rowspan="2" headerText="المنتج"/>
                                
                                <p:column  rowspan="2" headerText="المصنع"/>
                                

                                <p:column colspan="2" headerText="الافتتاحي"/>

                                <p:column colspan="2" headerText="المباع"/>

                                <p:column colspan="2" headerText="المتبقي"/>
                               <p:column  rowspan="2" headerText="السعر"/>

                            </p:row>
                            <p:row>
                                <p:column headerText="كراتين"/>
                                <p:column headerText="وزن"/>
                               <p:column headerText="كراتين"/>
                                <p:column headerText="وزن"/>
                               <p:column headerText="كراتين"/>
                                <p:column headerText="وزن"/>
                           
                            </p:row>
                        </p:columnGroup>

                        <p:subTable var="item" value="#{items.storeBean}">  
                            <p:column>
                                <h:outputText value="#{item.itemName}"/>
                            </p:column>
                           
                            <p:column>
                                <h:outputText value="#{item.factoryName}"/>
                            </p:column>
                            <p:column>
                                <h:outputText value="#{item.pkAtFromDate}"/>
                            </p:column>
                             <p:column>
                                <h:outputText value="#{item.quantityAtFromDate}"/>
                            </p:column>
                            <p:column>
                                <h:outputText value="#{item.buyedPk}"/>
                            </p:column>
                             <p:column>
                                <h:outputText value="#{item.buyedQuantity}"/>
                            </p:column>
                            <p:column>
                                <h:outputText value="#{item.remainderPk}"/>
                            </p:column>
                            <p:column>
                                <h:outputText value="#{item.remainderQuantity}"/>
                            </p:column>
                            <p:column>
                                <h:outputText value="#{item.itemPrice}"/>
                            </p:column>
                            <p:columnGroup type="footer">  
                                <p:row>  
                                    <p:column footerText="#{items.itemName}"/>  
                                    <p:column footerText="=========" />  
                                   
                                    <p:column footerText="#{items.totalPKAtFromDate}" />
                                   <p:column footerText="#{items.totalQuantityAtFromDate}" />
                                    <p:column footerText="#{items.totalBuyedPK}" />
                                    <p:column footerText="#{items.totalBuyedQuantity}" />
                                    <p:column footerText="#{items.totalRemainderPK}" />
                                    <p:column footerText="#{items.totalRemainderQuantity}" /> 
                                    <p:column footerText="#{items.totalItemPrice}" />  
                                </p:row>  
                            </p:columnGroup> 
                        </p:subTable>  
                    </p:dataTable>  
                </h:panelGroup>
                <br />
                <br />
                <center>
                    <h:panelGroup    rendered="${limits==0}">
                <h:outputText value=" مشترى"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="label label-info" >
                    <h:outputText value="#{inventoryStoreController.purchased}"/></span>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </h:panelGroup>
                <h:outputText value=" مباع"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="label label-info" >
                    <h:outputText value="#{inventoryStoreController.buyed}"/></span>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <h:panelGroup    rendered="${limits==0}">
                <h:outputText value=" صافى الربح"/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="label label-info" >
                    <h:outputText value="#{inventoryStoreController.profit}"/></span>
                    </h:panelGroup>
                </center>
                <br />
                <br />
            </h:form>
            <!-- end of the table -->

            <div class="form-inline">
                <!--               total-->
            </div>

        </ui:define>
    </ui:composition>
</html>